package com.edu.exam.entity.examination.paper;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 监考员实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：invigilator
 *
 * <p>监考员实体，记录监考人员的基本信息、资质认证、
 * 联系方式、可用时间等完整信息。支持监考员管理、
 * 工作量统计和冲突检测等功能。</p>
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Invigilator {

    /**
     * 监考员ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 监考员姓名
     */
    @Column(name = "invigilator_name", length = 50, nullable = false)
    private String invigilatorName;

    /**
     * 监考员编号
     */
    @Column(name = "invigilator_code", length = 20, nullable = false, unique = true)
    private String invigilatorCode;

    /**
     * 部门ID
     */
    @Column(name = "department_id", length = 32, nullable = false)
    private String departmentId;

    /**
     * 部门名称
     */
    @Column(name = "department_name", length = 100, nullable = false)
    private String departmentName;

    /**
     * 资质认证
     */
    @Column(name = "qualification", length = 50, nullable = false)
    private String qualification;

    /**
     * 监考员状态
     */
    @Column(name = "status", length = 20, nullable = false)
    private String status;

    /**
     * 联系电话
     */
    @Column(name = "contact_phone", length = 20)
    private String contactPhone;

    /**
     * 联系邮箱
     */
    @Column(name = "contact_email", length = 100)
    private String contactEmail;

    /**
     * 最高监考级别
     */
    @Column(name = "max_level", length = 20)
    private String maxLevel;

    /**
     * 专业领域
     */
    @Column(name = "specialization", length = 200)
    private String specialization;

    /**
     * 工作年限
     */
    @Column(name = "work_years")
    private Integer workYears;

    /**
     * 监考经验（监考次数）
     */
    @Column(name = "invigilation_experience")
    private Integer invigilationExperience;

    /**
     * 优先级
     */
    @Column(name = "priority")
    private Integer priority;

    /**
     * 最大月监考次数
     */
    @Column(name = "max_monthly_assignments")
    private Integer maxMonthlyAssignments;

    /**
     * 当前月监考次数
     */
    @Column(name = "current_monthly_assignments")
    private Integer currentMonthlyAssignments;

    /**
     * 备注
     */
    @Column(name = "remarks", length = 500)
    private String remarks;

    /**
     * 创建人ID
     */
    @Column(name = "created_by", length = 32, nullable = false)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新人ID
     */
    @Column(name = "updated_by", length = 32)
    private String updatedBy;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 版本号
     */
    @Version
    @Column(name = "version", nullable = false)
    private Integer version;

    /**
     * 可用时间列表
     */
    @OneToMany(mappedBy = "invigilator", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<InvigilatorAvailability> availabilities;

    /**
     * 监考安排详情列表
     */
    @OneToMany(mappedBy = "invigilator", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<InvigilationAssignmentDetail> assignmentDetails;

    /**
     * 工作量统计列表
     */
    @OneToMany(mappedBy = "invigilator", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<InvigilatorWorkloadStatistics> workloadStatistics;
}